package cn.edu.hbwe.book.dao;

import java.sql.Connection;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu.hbwe.book.entity.User;
import cn.edu.hbwe.book.utils.DBCPUtil;
import cn.edu.hbwe.book.utils.DuridUtil;

public class Uesrdao {
	public static void addUser(User user)  {
		QueryRunner qr=new QueryRunner();
			try {
				String sql = "insert into user(username,password,gender,email,telephone,introduce) values(?,?,?,?,?,?)";
				Connection conn=DuridUtil.getConn();
				qr.update(conn, sql,user.getUsername(),user.getPassword(),user.getGender(),user.getEmail(),user.getTelephone(),user.getIntroduce());//数据自己补
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		
		
			
			
		
	}
	public User findUserByUsernameAndPassword(String username, String password) throws SQLException {
		QueryRunner runner=new QueryRunner();
		String sql="select * from user where username=? and password=?";
		Connection conn=DuridUtil.getConn();
		User user =runner.query(conn, sql, new BeanHandler<User>(User.class),username,password);
		
		return user;
	}

}
